package a10_动态规划;

/**
 * <p>
 * a06_不同路径复习1
 * </p>
 *
 * @author flyduck
 * @since 2025/2/9
 */
public class a06_不同路径复习1 {
    public int uniquePaths(int m, int n) {
        //1、dp[i][j]含义，到达i,j有dp[i][j]条路径
        //2、递推公式：dp[i][j] = dp[i-1][j] + dp[i][j-1]
        //3、初始化 dp[1][1] = 1 dp[i][1] = 1 dp[1][j] = 1
        int[][] dp = new int[m+1][n+1];
        dp[1][1] = 1;
        for (int i = 2; i <= m; i++) {
            dp[i][1] = 1;
        }

        for (int j = 2; j <= n; j++) {
            dp[1][j] = 1;
        }

        for (int i = 2; i <= m; i++) {
            for (int j = 2; j <= n; j++) {
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
            }
        }

        return dp[m][n];

//        dp[2][2] -> dp[2][n]
//        dp[3][2] -> dp[3][n]
//        dp[m][2] -> dp[m][n]

    }
}
